package baseStructure;

import java.util.ArrayList;

/***
 * @author Ragnvald Fuglestein
 */

public abstract class Search {
	protected String name = null;

	public Search(String name) {
		this.name = name;
	}
	
	public Search() {}
	
	private ArrayList<ExtendedSearch> search = new ArrayList<>();
	
	/***
	 * 
	 * @param search
	 */
	public void addSearch(ExtendedSearch search) {
		this.search.add(search);
	}
	
	/**
	 * 
	 * @param name
	 * @return true if base matches search criteria
	 */
	public boolean matches(Base base) {
		if (this.name != null) {
			if (!base.hasNameCaseInsensitive(name)) return false;
		}
		
		for (ExtendedSearch s : search) {
			if (!base.matches(s)) {
				return false;
			}
		}
		
		return true;
	}
	
	public String getName() { return name; }
	
	public boolean hasName() { return name != null; }
	
	public String toString() {
		String str = "";
		if (name != null) str += name;
		
		return str;
	}
}
